/*
 * Copyright (c) 2013.
 * 游戏服务器核心代码编写人陈磊拥有使用权
 * 联系方式：E-mail:13638363871@163.com ;qq:502959937
 * 个人博客主页：http://my.oschina.net/chenleijava
 */

package com.dc.gameserver.serverCore.model.gamemodel.script;

import com.dc.gameserver.baseConfig.Config;
import com.dc.gameserver.exceptions.dataException;
import com.dc.gameserver.exceptions.logicException;
import com.dc.gameserver.serverCore.model.gamemodel.*;
import javolution.util.FastMap;
import javolution.util.FastTable;
import org.apache.log4j.xml.DOMConfigurator;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.dom4j.tree.DefaultElement;

import java.io.FileInputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * @author 石头哥哥
 *         Date: 13-11-29</br>
 *         Time: 上午11:21</br>
 *         Package: com.dc.gameserver.serverCore.model.Gamemodel</br>
 *         注解：脚本工厂，加载游戏数据配置文件
 */
@SuppressWarnings("unchecked")
public class  ScriptFactory {

    public final static SimpleDateFormat FORMAT;

    static {
        FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    FastMap<String, String> AttributeMap=null;
    FastTable<String> AttributeValueList=null;


    /********游戏数据资源文件加载缓存************************************/
    public static FastMap<Integer,StateModel> stateModelFastMap=new FastMap<Integer, StateModel>();    //角色境界
    public static FastMap<Integer,EquipmentModel> equipmentModelFastMap=new FastMap<Integer, EquipmentModel>();    //装备
    public static FastMap<Integer,BookModel> bookModelFastMap=new FastMap<Integer, BookModel>();  //秘籍
    public static FastMap<Integer,PropsModel>itemModelFastMap=new FastMap<Integer, PropsModel>();    //道具
    public static FastMap<Integer,EffectiveModel> effectiveModelFastMap=new FastMap<Integer, EffectiveModel>();   //特效
    public static FastMap<Integer,AreaModel> areaModelFastMap=new FastMap<Integer, AreaModel>();     //地图
    public static FastMap<Integer,PointUnlockModel> pointUnlockModelFastMap=new FastMap<Integer, PointUnlockModel>();  //未解锁
    public static FastMap<Integer,LevelModel> pointModelFastMap=new FastMap<Integer, LevelModel>();     //关卡
    public static FastMap<Integer,MonsterModel> monsterModelFastMap=new FastMap<Integer, MonsterModel>();     //怪物
    public static FastMap<Integer,SkillModel> skillModelFastMap=new FastMap<Integer, SkillModel>();     //技能
    public static FastMap<Integer,SkillTypeModel> skillTypeModelFastMap=new FastMap<Integer, SkillTypeModel>();     //技能类型
    public static FastMap<Integer,CardNumModel> cardNumModelFastMap=new FastMap<Integer, CardNumModel>();     //出牌数量模型 ,对应相应的境界编号
    public static FastMap<Integer,SpriteModel> spriteModelFastMap=new FastMap<Integer, SpriteModel>();     //14（灵脉），15（蒲团），16（灵泉）
    public static BaseRoleModel[] baseRoleModel=new BaseRoleModel[1];//角色基础信息model




    //区域 对应 主线关卡
    public static FastMap<Integer,FastTable<LevelModel>> mainLevelFastMap=new FastMap<Integer, FastTable<LevelModel>>();
    //区域 对应 神识关卡
     @Deprecated
    public static FastMap<Integer,FastTable<LevelModel>> soulLevelFastMap=new FastMap<Integer, FastTable<LevelModel>>();
    @Deprecated
    public static FastTable<LevelModel> soulLevelList=new FastTable<LevelModel>();//神识关卡列表


    /**
     *脚本工厂 加载xml配置
     */
    private  ScriptFactory(){
        try {
            AttributeMap=new FastMap<String, String>();  //属性容器
            AttributeValueList=new FastTable<String>();// AttributeValue
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_STATE,"state"); //角色境界配置
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_SPRITE,"spirit"); //角色境界配置
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_CARD_NUM_MODEL,"stateCard");//出牌数量模型 ,对应相应的境界编号
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_SKILLTYPE,"skillType"); //
            IntiGameXmlForSkill(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_SKILL, "Skill");
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_MONSTER,"monster");
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_EQUIPMENT,"equip");  //装备
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_BOOKS,"books");  //秘籍
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_ITEM,"item"); //道具
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_EFFECTIVE,"effectType"); //特效
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_AREA,"area");      //地图
            IntiGameXML(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_LEVEL_UNLOCK_TYPE,"unlockType"); //未解锁
            IntiGameXmlForLevelItem(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_LEVEL, "level");     //关卡
            IntiGameXMLForRole(Config.DEFAULT_VALUE.FILE_PATH.GAME_XML_DATA_ROLE);  //角色基础model

            IntiareasLevelList();
        }catch (dataException e){
           throw new logicException("加载游戏脚本异常... ...",e);
        }
        finally {
            AttributeMap=null;
            AttributeValueList=null;
        }
    }

    /**area---level  1:n**/
    public static void IntiareasLevelList(){
        for (FastMap.Entry<Integer,AreaModel> entry:areaModelFastMap.entrySet()){
            AreaModel areaModel=entry.getValue();
            int areaID=areaModel.getId();
            FastTable<LevelModel> mainLevelModelFastTable=new FastTable<LevelModel>();
            FastTable<LevelModel> soulLevelModelFastTable=new FastTable<LevelModel>(); //神识关卡列表
            for (FastMap.Entry<Integer,LevelModel> LevelEntry:pointModelFastMap.entrySet()) {
                 LevelModel levelModel=LevelEntry.getValue();
                //主线关卡
                 if (areaID==levelModel.getAreaID()&&levelModel.getLevelType()== 0x1){
                     mainLevelModelFastTable.addLast(levelModel); //add last
                 }
                //神识关卡
                if (areaID==levelModel.getAreaID()&&levelModel.getLevelType()== 0x2){
                    soulLevelModelFastTable.addLast(levelModel);
                    soulLevelList.addLast(levelModel);
                }
            }
            mainLevelModelFastTable.sort();//排序主线关卡
            soulLevelModelFastTable.sort();
            mainLevelFastMap.put(areaID,mainLevelModelFastTable);
            soulLevelFastMap.put(areaID,soulLevelModelFastTable);
        }

    }
    /**
     *mapper  model
     */
    private enum xmlMapper{
        STATE("state",StateModel.class,stateModelFastMap),
        SPRITE("spirit",SpriteModel.class,spriteModelFastMap),
        STATE_CARD_NUM("stateCard",CardNumModel.class,cardNumModelFastMap),
        SKILLTYPE("skillType",SkillTypeModel.class,skillTypeModelFastMap),
        SKILL("Skill",SkillModel.class,skillModelFastMap),
        MONSTER("monster",MonsterModel.class,monsterModelFastMap),
        EQUIPMENT("equip",EquipmentModel.class,equipmentModelFastMap),
        BOOK("books",BookModel.class,bookModelFastMap),
        ITEM("item",PropsModel.class,itemModelFastMap),
        EFFECTIVE("effectType",EffectiveModel.class,effectiveModelFastMap)  ,
        AREA("area",AreaModel.class,areaModelFastMap),
        LEVEL_UNLOCK_TYPE("unlockType",PointUnlockModel.class,pointUnlockModelFastMap)  ,
        LEVEL("level",LevelModel.class,pointModelFastMap),  // may be change

        ;
        private final String flag;       //加载物品类型  item , props, task
        private final Class<?> cls;   //model   class
        private FastMap map;      //存储model实体 map

        /**
         * mapper
         * @param flag
         * @param cls
         * @param map
         */
        private xmlMapper(final String flag,final Class<?> cls,FastMap map){
            this.flag = flag;
            this.cls= cls;
            this.map = map;
        }
        private String getFlag() {
            return flag;
        }

        public Class<?> getCls() {
            return cls;
        }
        public FastMap getMap() {
            return map;
        }
        /**
         *
         * @return
         */
        public static xmlMapper getXmlMapperByFlag(String flag){
            for (xmlMapper mapper:xmlMapper.values()){
                if (mapper.getFlag().equalsIgnoreCase(flag)){
                    return mapper;
                }
            }
            return null;
        }

    }

    /**
     * 加载角色基础属性model
     * @param sourcesXML
     */
    private void IntiGameXMLForRole(String sourcesXML){
        Document doc = null;
        try {
            InputStream inputStream = new FileInputStream(sourcesXML);
            SAXReader saxReader = new SAXReader();
            doc = saxReader.read(inputStream);
        } catch (Exception e) {
            throw  new dataException("加载游戏资源数据异常",e);
        }
        if (doc!=null){
            //获取根节点
            Element root = doc.getRootElement();
            //迭代model节点
            for(Iterator iterator=root.elementIterator();iterator.hasNext();){
                Element element= (Element) iterator.next();
                //迭代model属性
                for (Iterator vos = element.attributeIterator(); vos.hasNext();){
                    Attribute attribute= (Attribute) vos.next();
                    AttributeValueList.addLast(attribute.getValue());
                }
                baseRoleModel[0]=(BaseRoleModel) List2Object(AttributeValueList,BaseRoleModel.class);
            }
        }
    }

    /**
     * 加载 游戏资源 xml，读取属性方式
     * @param sourcesXML
     */
    private void IntiGameXML(String sourcesXML,String flag){
         xmlMapper mapper=xmlMapper.getXmlMapperByFlag(flag);
         Document doc = null;
            try {
                InputStream inputStream = new FileInputStream(sourcesXML);
                SAXReader saxReader = new SAXReader();
                doc = saxReader.read(inputStream);
            } catch (Exception e) {
                 throw  new dataException("加载游戏资源数据异常",e);
            }
            if (doc!=null){
                //获取根节点
                Element root = doc.getRootElement();
                    //迭代model节点
                    for(Iterator iterator=root.elementIterator();iterator.hasNext();){
                        Element element= (Element) iterator.next();
                        //迭代model属性
                        for (Iterator vos = element.attributeIterator(); vos.hasNext();){
                            Attribute attribute= (Attribute) vos.next();
//                            String name=attribute.getName();
//                            String value= attribute.getValue() ;
//                            LOGGER.debug(name+":"+value);
                            AttributeMap.put(attribute.getName(),attribute.getValue());
                        }
                        //将属性映射到model实体上
                        Object o=map2Object(AttributeMap, mapper.getCls());
                        if (o!=null) {
                            Model model= (Model) o;
                            mapper.getMap().put(model.getId(),model);
                        }else {
                            throw new dataException("数据加载异常... ...,o is null");
                        }
                }
           }
    }

    /**
     *   加载 游戏资源 xml，读取属性方式
     * @param sourcesXML
     * @param flag
     */
    public void IntiGameXmlForSkill(String sourcesXML,String flag){
        xmlMapper mapper=xmlMapper.getXmlMapperByFlag(flag);
        Document doc = null;
        try {
            InputStream inputStream = new FileInputStream(sourcesXML);
            SAXReader saxReader = new SAXReader();
            doc = saxReader.read(inputStream);
        } catch (Exception e) {
            throw  new dataException("加载游戏资源数据异常",e);
        }
        if (doc!=null){
            //获取根节点
            Element root = doc.getRootElement();
            //迭代model节点
            for(Iterator iterator=root.elementIterator();iterator.hasNext();){
                Element element= (Element) iterator.next();
                FastTable<singleSkillModel>AttributeList= new FastTable<singleSkillModel>();
                if (element.hasContent()){
                    for (Iterator childIterator=element.nodeIterator();childIterator.hasNext();){
                        Object childElement=childIterator.next();
                        if (childElement.getClass().equals(DefaultElement.class)) {
                            DefaultElement defaultElement= (DefaultElement) childElement;
                            for (Iterator _childIterator=defaultElement.attributeIterator();_childIterator.hasNext();){
                                Attribute attribute= (Attribute) _childIterator.next();
//                             String name=attribute.getName();
//                             String value= attribute.getValue() ;
//                             LOGGER.debug(name+":"+value);
                                AttributeValueList.addLast(attribute.getValue());
                            }
                            singleSkillModel  singleSkillModel= (singleSkillModel) List2Object(AttributeValueList,singleSkillModel.class);
                            AttributeList.addFirst(singleSkillModel);
                        }
                    }
                }

                //迭代model属性
                for (Iterator vos = element.attributeIterator(); vos.hasNext();){
                    Attribute attribute= (Attribute) vos.next();
//                    String name=attribute.getName();
//                    String value= attribute.getValue() ;
//                    LOGGER.debug(name+":"+value);
                    AttributeMap.put(attribute.getName(),attribute.getValue());
                }
                //将属性映射到model实体上
                Object o=null;
                if (AttributeList!=null){
                    o=map2ObjectWithSkillModel(AttributeMap, mapper.getCls(), AttributeList);
                } else {
                    throw new dataException("数据加载异常... ...,map2Object");
                }
                if (o!=null) {
                    Model model= (Model) o;
                    mapper.getMap().put(model.getId(),model);
                }else {
                    throw new dataException("数据加载异常... ...,o is null");
                }
            }
        }
    }


    /**
     *   加载 游戏资源 xml，读取属性方式
     * @param sourcesXML
     * @param flag
     */
    public void IntiGameXmlForLevelItem(String sourcesXML,String flag){
        xmlMapper mapper=xmlMapper.getXmlMapperByFlag(flag);
        Document doc = null;
        try {
            InputStream inputStream = new FileInputStream(sourcesXML);
            SAXReader saxReader = new SAXReader();
            doc = saxReader.read(inputStream);
        } catch (Exception e) {
            throw  new dataException("加载游戏资源数据异常",e);
        }
        if (doc!=null){
            //获取根节点
            Element root = doc.getRootElement();
            //迭代model节点
            for(Iterator iterator=root.elementIterator();iterator.hasNext();){
                Element element= (Element) iterator.next();
                FastTable<itemDropModel>AttributeList= new FastTable<itemDropModel>();
                if (element.hasContent()){
                   for (Iterator childIterator=element.nodeIterator();childIterator.hasNext();){
                       Object childElement=childIterator.next();
                      if (childElement.getClass().equals(DefaultElement.class)) {
                          DefaultElement defaultElement= (DefaultElement) childElement;
                         for (Iterator _childIterator=defaultElement.attributeIterator();_childIterator.hasNext();){
                             Attribute attribute= (Attribute) _childIterator.next();
//                             String name=attribute.getName();
//                             String value= attribute.getValue() ;
//                             LOGGER.debug(name+":"+value);
                             AttributeValueList.addLast(attribute.getValue());
                         }
                       itemDropModel  dropModel= (itemDropModel) List2Object(AttributeValueList,itemDropModel.class);
                       AttributeList.addLast(dropModel);
                      }
                   }
                }

                //迭代model属性
                for (Iterator vos = element.attributeIterator(); vos.hasNext();){
                    Attribute attribute= (Attribute) vos.next();
//                    String name=attribute.getName();
//                    String value= attribute.getValue() ;
//                    LOGGER.debug(name+":"+value);
                    AttributeMap.put(attribute.getName(),attribute.getValue());
                }
                //将属性映射到model实体上
                Object o=null;
                if (AttributeList!=null){
                     o=map2Object(AttributeMap, mapper.getCls(),AttributeList);
                } else {
                    throw new dataException("数据加载异常... ...,map2Object");
                }

                if (o!=null) {
                    Model model= (Model) o;
                    mapper.getMap().put(model.getId(),model);
                }else {
                    throw new dataException("数据加载异常... ...,o is null");
                }
            }
        }
    }

    /**
     *
     * @param list
     * @param classType
     * @return
     */
    private Object List2Object(List<String> list,Class classType){
        Object objectCopy = null;
        try {
            objectCopy = classType.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 获得对象的所有属性
        Field[] fields = classType.getDeclaredFields();
        int length=fields.length;
        for (int i=0;i!=length;++i){
            // 获取数组中对应的属性
            String fieldName = fields[i].getName();
            String stringLetter = fieldName.substring(0, 1).toUpperCase();

            // 获得相应属性的setXXX方法名称
            String setName = "set" + stringLetter + fieldName.substring(1);
            // 获取相应的setXXX方法
            Method setMethod = null;
            try {
                setMethod = classType.getMethod(setName, new Class[] {fields[i]
                        .getType()});     //根据方法名获取set方法
            } catch (Exception e) {
                continue;
            }
            // 将获取的数据注入到model中
            try {
                Class classes[]  = setMethod.getParameterTypes();
                Object value = null;
                String fieldValue=list.get(i);
                    if(fieldValue == null || "".equals(fieldValue)){
                        continue;
                    }else if(classes[0].equals(Date.class)){
                        value = FORMAT.parse(fieldValue);
                    }else if(classes[0].equals(Integer.class)){
                        value = Integer.valueOf(fieldValue);
                    }else if(classes[0].equals(Long.class)){
                        value = Long.valueOf(fieldValue);
                    }else if(classes[0].equals(Float.class)){
                        value = Float.valueOf(fieldValue);
                    }else if(classes[0].equals(Double.class)){
                        value = Double.valueOf(fieldValue);
                    }else if (classes[0].equals(Boolean.class)){
                        value =Boolean.valueOf(fieldValue);
                    }else if (classes[0].equals(Byte.class)){
                        value=Byte.valueOf(fieldValue);
                    }else {
                        value = fieldValue;     //string
                    }
                    setMethod.invoke(objectCopy, value);
            } catch (Exception ignored) {

            }
        }
          list.clear();
          return objectCopy;
    }

    /**
     * 通过反射，注入model属性
     * @param map
     * @param classType
     * @return  Object
     */
    private Object map2Object(FastMap<String, String> map,Class classType){
        Object objectCopy = null;
        try {
            objectCopy = classType.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 获得对象的所有属性
        Field[] fields = classType.getDeclaredFields();

        for (Field field : fields) {
            // 获取数组中对应的属性
            String fieldName = field.getName();
            String stringLetter = fieldName.substring(0, 1).toUpperCase();

            // 获得相应属性的setXXX方法名称
            String setName = "set" + stringLetter + fieldName.substring(1);

            // 获取相应的setXXX方法
            Method setMethod = null;
            try {
                setMethod = classType.getMethod(setName, new Class[] {field
                        .getType()});     //根据方法名获取set方法
            } catch (Exception e) {
                continue;
            }
            // 将获取的数据注入到model中
            try {
                Class classes[]  = setMethod.getParameterTypes();
                Object value = null;
                String fieldValue = map.get(fieldName);    //对应的值
                if(fieldValue == null || "".equals(fieldValue)){
                    continue;
                }else if(classes[0].equals(Date.class)){
                    value = FORMAT.parse(fieldValue);
                }else if(classes[0].equals(Integer.class)){
                    value = Integer.valueOf(fieldValue);
                }else if(classes[0].equals(Long.class)){
                    value = Long.valueOf(fieldValue);
                }else if(classes[0].equals(Float.class)){
                    value = Float.valueOf(fieldValue);
                }else if(classes[0].equals(Double.class)){
                    value = Double.valueOf(fieldValue);
                }else if (classes[0].equals(Boolean.class)){
                    value =Boolean.valueOf(fieldValue);
                }else if (classes[0].equals(Byte.class)){
                    value=Byte.valueOf(fieldValue);
                }  else {
                    value = fieldValue;     //string
                }
                setMethod.invoke(objectCopy, value);
            } catch (Exception ignored) {
            }
        }
        map.clear();
        return objectCopy;
    }


    /**
     * 定制 加载配置 方案
     *  {@link com.dc.gameserver.serverCore.model.gamemodel.SkillModel#(javolution.util.FastTable)}
     * @param map
     * @param classType
     * @param singleSkillModels
     * @return
     */
    private Object map2ObjectWithSkillModel(FastMap<String, String> map,Class classType,FastTable<singleSkillModel> singleSkillModels) {
        Object objectCopy = null;
        try {
            objectCopy = classType.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 获得对象的所有属性
        Field[] fields = classType.getDeclaredFields();

        for (Field field : fields) {
            // 获取数组中对应的属性
            String fieldName = field.getName();
            String stringLetter = fieldName.substring(0, 1).toUpperCase();

            // 获得相应属性的setXXX方法名称
            String setName = "set" + stringLetter + fieldName.substring(1);

            // 获取相应的setXXX方法
            Method setMethod = null;
            try {
                setMethod = classType.getMethod(setName, new Class[] {field
                        .getType()});     //根据方法名获取set方法
            } catch (Exception e) {
                continue;
            }
            if (setName.equalsIgnoreCase("setSingleSkillModelFastTable")) {
                try {
                    setMethod.invoke(objectCopy, singleSkillModels);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
                continue;
            }
            // 将获取的数据注入到model中
            try {
                Class classes[]  = setMethod.getParameterTypes();
                Object value = null;
                String fieldValue = map.get(fieldName);    //对应的值
                if(fieldValue == null || "".equals(fieldValue)){
                    continue;
                }else if(classes[0].equals(Date.class)){
                    value = FORMAT.parse(fieldValue);
                }else if(classes[0].equals(Integer.class)){
                    value = Integer.valueOf(fieldValue);
                }else if(classes[0].equals(Long.class)){
                    value = Long.valueOf(fieldValue);
                }else if(classes[0].equals(Float.class)){
                    value = Float.valueOf(fieldValue);
                }else if(classes[0].equals(Double.class)){
                    value = Double.valueOf(fieldValue);
                }else if (classes[0].equals(Boolean.class)){
                    value =Boolean.valueOf(fieldValue);
                } else if (classes[0].equals(Byte.class)){
                    value=Byte.valueOf(fieldValue);
                } else {
                    value = fieldValue;     //string
                }
                setMethod.invoke(objectCopy,value);
            } catch (Exception ignored) {
            }
        }
        map.clear();
        return objectCopy;
    }


    /**
     * 定制 加载配置 方案
     *  {@link com.dc.gameserver.serverCore.model.gamemodel.LevelModel#setItemDropModelFastTable(javolution.util.FastTable)}
     * @param map
     * @param classType
     * @param itemDropModels
     * @return
     */
    private Object map2Object(FastMap<String, String> map,Class classType,FastTable<itemDropModel> itemDropModels) {
        Object objectCopy = null;
        try {
            objectCopy = classType.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 获得对象的所有属性
        Field[] fields = classType.getDeclaredFields();

        for (Field field : fields) {
            // 获取数组中对应的属性
            String fieldName = field.getName();
            String stringLetter = fieldName.substring(0, 1).toUpperCase();

            // 获得相应属性的setXXX方法名称
            String setName = "set" + stringLetter + fieldName.substring(1);

            // 获取相应的setXXX方法
            Method setMethod = null;
            try {
                setMethod = classType.getMethod(setName, new Class[] {field
                        .getType()});     //根据方法名获取set方法
            } catch (Exception e) {
                continue;
            }
            if (setName.equalsIgnoreCase("setItemDropModelFastTable")) {
                try {
                    setMethod.invoke(objectCopy, itemDropModels);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
                continue;
            }
            // 将获取的数据注入到model中
            try {
                Class classes[]  = setMethod.getParameterTypes();
                Object value = null;
                String fieldValue = map.get(fieldName);    //对应的值
                if(fieldValue == null || "".equals(fieldValue)){
                   continue;
                }else if(classes[0].equals(Date.class)){
                    value = FORMAT.parse(fieldValue);
                }else if(classes[0].equals(Integer.class)){
                    value = Integer.valueOf(fieldValue);
                }else if(classes[0].equals(Long.class)){
                    value = Long.valueOf(fieldValue);
                }else if(classes[0].equals(Float.class)){
                    value = Float.valueOf(fieldValue);
                }else if(classes[0].equals(Double.class)){
                    value = Double.valueOf(fieldValue);
                }else if (classes[0].equals(Boolean.class)){
                    value =Boolean.valueOf(fieldValue);
                }else if (classes[0].equals(Byte.class)){
                    value=Byte.valueOf(fieldValue);
                }  else {
                    value = fieldValue;     //string
                }
                setMethod.invoke(objectCopy, value);
            } catch (Exception ignored) {
            }
        }
        map.clear();
        return objectCopy;
    }

    /**
     * 单例对象
     * @return
     */
    public static ScriptFactory getInstance(){
        return SingletonHolder._instance;
    }

    //单例
    private static class SingletonHolder{
        private static final ScriptFactory _instance = new ScriptFactory();
    }


    public static void main(String[]args){
        DOMConfigurator.configure(Config.DEFAULT_VALUE.FILE_PATH.LOG4J);
        ScriptFactory.getInstance();
        SpriteModel levelModelFastTable1=ScriptFactory.spriteModelFastMap.get(11810003);
//        FastTable<LevelModel> levelModelFastTable2=ScriptFactory.mainLevelFastMap.get(2);
        System.out.println(levelModelFastTable1);
    }
}
